﻿using System;
using System.Collections.Generic;
using System.Data;
using NBearLite;
using Xin478.CSWork.Common;

namespace Xin478.CSWork.DomainModel
{
    public class RemindModel
    {
        public static IList<RemindInfo> GetList(Database db, int from, int pageSize, WhereClip where, QueryColumn orderBy, bool isAsc)
        {
            IList<RemindInfo> ris = new List<RemindInfo>();

            System.Data.IDataReader dr = db.Select(MyWork.Reminds,
                MyWork.Reminds.Id,
                MyWork.Reminds.UserId,
                MyWork.Reminds.Detail,
                MyWork.Reminds.AddTime,
                MyWork.Reminds.DefiniteDate,
                MyWork.Reminds.DefiniteTime,
                MyWork.Reminds.DelayTime,
                MyWork.Reminds.Interval,
                MyWork.Reminds.PlanType,
                MyWork.Reminds.LastSureTime
                ).Where(where)
                .SetSelectRange(pageSize, from, orderBy)
                .OrderBy(isAsc? orderBy.Asc: orderBy.Desc).ToDataReader();

            while (dr.Read())
            {
                RemindInfo ri = new RemindInfo();
                ri.Id = dr.GetInt32(0);
                ri.UserId = dr.GetInt32(1);
                ri.Detail = dr.GetString(2);
                ri.AddTime = dr.GetDateTime(3);
                if (!dr.IsDBNull(4)) ri.DefiniteDate = dr.GetDateTime(4).ToString("yyyy-MM-dd");
                ri.DefiniteTime = dr.GetInt32(5);
                ri.DelayTime = dr.GetInt32(6);
                ri.Interval = dr.GetInt32(7);
                ri.PlanType = dr.GetInt32(8);
                if (!dr.IsDBNull(9)) ri.LastSureTime = dr.GetDateTime(9);
                ris.Add(ri);
            }
            return ris;
        }
    }
}
